﻿using System;
using System.Collections.Generic;

namespace AT.IBMS.Framework.Tools
{
    public static class GenerateRandomTool
    {

        private static object objLock = new object();
        private static decimal prevId = 0;

        /// <summary>
        /// 随机生成id。
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public static string CreateNewId(this Tool t)
        {

            decimal id;

            id = Convert.ToDecimal(DateTime.Now.ToString("yyyyMMddHHmmssffff") + "0001");

            lock (objLock)
            {

                while (id <= prevId)
                {
                    id++;
                }

                prevId = id;

            }

            return id.ToString();
        }

        /// <summary>
        /// 创建0-9的随机数字集合。
        /// </summary>
        /// <param name="t"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static List<int> CreateNumber(this Tool t, int count = 1)
        {

            List<int> result;
            Random random;

            result = new List<int>();
            random = new Random();

            for (int i = 0; i < count; i++)
            {
                result.Add(random.Next(0, 10));
            }

            return result;

        }
    }
}
